package com.jiuyou.clientController.enterprise;

import com.jiuyou.clientController.base.ClientBaseController;
import com.ruoyi.common.constant.DicConstants;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.enterprise.domain.Enterprise;
import com.ruoyi.enterprise.service.IEnterpriseService;
import com.ruoyi.qualifica.service.IQualificaService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 企业信息Controller
 *
 * @author ruoyi
 * @date 2025-05-06
 */
@RestController
@RequestMapping("/client/enterprise")
public class ClientEnterpriseClientController extends ClientBaseController {

    @Autowired
    private IQualificaService qualificaService;

    @Autowired
    private IEnterpriseService enterpriseService;

    /**
     * 查询所有
     * */
    @GetMapping("/listQita")
    public AjaxResult listQita()
    {
        Enterprise enterprise=new Enterprise();
        enterprise.setType("qita");
        List<Enterprise> list = enterpriseService.selectEnterpriseList(enterprise);
        return AjaxResult.success(list);
    }

    /**
     * 所有企业遍历
     * */
    @GetMapping("/listAll")
    public AjaxResult listAll(Enterprise enterprise)
    {
        List<Enterprise> list = enterpriseService.selectEnterpriseList(enterprise);
        return AjaxResult.success(list);
    }

    /**
     * 查询企业信息列表
     */
    @ApiOperation("企业信息列表")
    @GetMapping("/list")
    public TableDataInfo list(Enterprise enterprise)
    {
        startPage();
        List<Enterprise> list = enterpriseService.selectEnterpriseList(enterprise);
        return getDataTable(list);
    }

    /**
     * 导出企业信息列表
     */
    @GetMapping("/export")
    public AjaxResult export(Enterprise enterprise)
    {
        List<Enterprise> list = enterpriseService.selectEnterpriseList(enterprise);
        ExcelUtil<Enterprise> util = new ExcelUtil<Enterprise>(Enterprise.class);
        return util.exportExcel(list, "企业信息数据");
    }

    /**
     * 获取企业信息详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(enterpriseService.selectEnterpriseById(id));
    }

    /**
     * 新增企业信息
     */
    @PostMapping
    public AjaxResult add(@RequestBody Enterprise enterprise)
    {
        return toAjax(enterpriseService.insertEnterprise(enterprise));
    }

    /**
     * 修改企业信息
     */
    @PutMapping
    public AjaxResult edit(@RequestBody Enterprise enterprise)
    {
        enterprise.setUpdateType(DicConstants.BUSINESS_Manager.getCode());
        return toAjax(enterpriseService.updateEnterprise(enterprise));
    }

    /**
     * 删除企业信息
     */
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(enterpriseService.logicDeleteEnterprise(ids,DicConstants.BUSINESS_Manager.getCode(), SecurityUtils.getUserId()));
    }

}
